package com.alipay.menu;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alipay.api.AlipayClient;
import com.alipay.api.domain.AlipayOpenPublicMenuCreateModel;
import com.alipay.api.domain.AlipayOpenPublicMenuModifyModel;
import com.alipay.api.domain.ButtonObject;
import com.alipay.api.domain.SubButton;
import com.alipay.api.request.AlipayOpenPublicMenuCreateRequest;
import com.alipay.api.request.AlipayOpenPublicMenuModifyRequest;
import com.alipay.api.request.AlipayOpenPublicMenuQueryRequest;
import com.alipay.api.response.AlipayOpenPublicMenuCreateResponse;
import com.alipay.api.response.AlipayOpenPublicMenuModifyResponse;
import com.alipay.api.response.AlipayOpenPublicMenuQueryResponse;
import com.alipay.constants.AlipayServiceEnvConstants;
import com.alipay.factory.AlipayAPIClientFactory;

import net.sf.json.JSONObject;

/**
 * 服务窗菜单相关接口调用示例
 * 
 * @author liliang
 *
 */
public class AlipayPublicMenu {
	
	public static void main(String[] args) {
		createMenu();
		//queryMenu();
//		modifyMenu();
	}

	// 创建服务窗菜单信息
	public static void createMenu() {
		AlipayClient alipayClient = AlipayAPIClientFactory.getAlipayClient();
		AlipayOpenPublicMenuCreateRequest request = new AlipayOpenPublicMenuCreateRequest();
		AlipayOpenPublicMenuCreateModel model = new AlipayOpenPublicMenuCreateModel();
		
		List<ButtonObject> list = new ArrayList<ButtonObject>();
		ButtonObject button1 = new ButtonObject();
		button1.setName("线路查询");
		button1.setActionType("link");
		//button1.setActionParam("http://10.100.235.123:8080/alipay/alipay/www/index.html#/lineQuery");
		
		button1.setActionParam("http://139.129.211.54:8086/alipay/alipay/lineQuery.do");
		//http://actioning.ngrok.cc/ServiceWindow_Demo/index3.html
		list.add(button1);
		
		ButtonObject button2 = new ButtonObject();
		button2.setName("邀请好友");
		
		//添加子菜单
		List<SubButton> subButtonList = new ArrayList<SubButton>();
		SubButton subButton1 = new SubButton();
		subButton1.setName("二维码");
		subButton1.setActionType("link");
		subButton1.setActionParam("http://actioning.ngrok.cc/ServiceWindow_Demo/generalize.do?type=1");
		subButtonList.add(subButton1);
		
		SubButton subButton2 = new SubButton();
		subButton2.setName("线路详情");
		subButton2.setActionType("link");
		subButton2.setActionParam("http://10.100.235.123:8080/alipay/alipay/www/index.html#/lineDetail");
		//subButton2.setActionParam("http://actioning.ngrok.cc/ServiceWindow_Demo/generalize.do?type=2");
		subButtonList.add(subButton2);
		
		button2.setSubButton(subButtonList);
		list.add(button2);
		
		/*ButtonObject button3 = new ButtonObject();
		button3.setName("联系我们");
		button3.setActionType("tel");
		button3.setActionParam("13419657975");
		list.add(button3);*/
		
		ButtonObject button4 = new ButtonObject();
		button4.setName("我要开卡");
		button4.setActionType("link");
		button4.setActionParam("https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id="+AlipayServiceEnvConstants.APP_ID+"&scope=auth_user,auth_ecard&redirect_uri=http://actioning.ngrok.cc/ServiceWindow_Demo/openCard.do");
		list.add(button4);
		
		model.setButton(list);
		
		request.setBizModel(model);
		AlipayOpenPublicMenuCreateResponse response = null;
		try {
			 response = alipayClient.execute(request);
			 System.out.println(response.getBody());
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	// 查询服务窗菜单信息
	public static void queryMenu() {
		AlipayClient alipayClient = AlipayAPIClientFactory.getAlipayClient();
		AlipayOpenPublicMenuQueryRequest request = new AlipayOpenPublicMenuQueryRequest();
		AlipayOpenPublicMenuQueryResponse response = null;
		try {
			response = alipayClient.execute(request);
			System.out.println(response.getBody());
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	// 修改服务窗菜单信息
	public static void modifyMenu() {
		AlipayClient alipayClient = AlipayAPIClientFactory.getAlipayClient();
		AlipayOpenPublicMenuModifyRequest request = new AlipayOpenPublicMenuModifyRequest();
		AlipayOpenPublicMenuModifyModel model = new AlipayOpenPublicMenuModifyModel();
		List<ButtonObject> list = new ArrayList<ButtonObject>();
		ButtonObject button = new ButtonObject();
		button.setName("测试");
		button.setActionType("link");
		button.setActionParam("www.baidu.com");
		list.add(button);
		model.setButton(list);
		request.setBizModel(model);
		AlipayOpenPublicMenuModifyResponse response = null;
		try {
			 response = alipayClient.execute(request);
			 System.out.println(response.getBody());
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
}
